package org.mparts.server.domain;

import java.io.Serializable;
import javax.persistence.*;

import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;

import java.util.HashSet;
import java.util.List;
import java.util.Set;


/**
 * The persistent class for the auto database table.
 * 
 */
@Entity
public class Auto extends EntityBase implements Serializable {
	private static final long serialVersionUID = 1L;
	private String name;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "auto", fetch = FetchType.EAGER, targetEntity = Model.class)
    //@Fetch(FetchMode.JOIN)
    @Fetch(FetchMode.SUBSELECT)
    private Set<Model> models;

	public Auto() {
	}


	public String getName() {
		return this.name;
	}

	public void setName(String name) {
		this.name = name;
	}
	
	public void addModel( Model model ) {
		getModels().add(model);
		model.setAuto(this);
	}


	//bi-directional many-to-one association to Model
//	@OneToMany(mappedBy="auto")
//    @OneToMany(cascade = CascadeType.ALL, mappedBy = "auto", fetch = FetchType.EAGER, targetEntity = Model.class)
//    @JoinTable(name = "model", joinColumns = { @JoinColumn(name = "id") }, inverseJoinColumns = { @JoinColumn(name = "auto_id") })
	public Set<Model> getModels() {
		if ( models == null ) {
			models = new HashSet<Model>();
		}
		return this.models;
	}

	public void setModels(Set<Model> models) {
		this.models = models;
	}

}